import java.util.Scanner;

/**
 * @Title: 小红的dfs
 * @Author 贾金博
 * @Package PACKAGE_NAME
 * @Date 2024/3/8 10:49
 * @description:
 */
public class 小红的dfs {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[][] a = new char[10][10];
        char[][] b = new char[10][10];

        for(int i = 1; i <= 3; ++ i ) {
            String s = sc.next();
            for(int j = 0; j < 3; ++ j ) {
                a[i][j + 1] = s.charAt(j);
                b[i][j + 1] = s.charAt(j);
            }
        }
        String t = "dfs";

        int ret = 100;
        for(int k = 1; k <= 3; ++ k ) { // 枚举的是在第几行
            int h = 0, l = 0;
            a = b;
            for(int i = 1; i <= 3; ++ i ) {
                if(a[k][i] != t.charAt(i - 1)) {
                    h++;
                   // a[k][i] = t.charAt(i - 1);
                }
            }

            for(int j = 1; j <= 3; ++ j ) {
                if(a[j][k] != t.charAt(j - 1)) {
                    l++;
                }
            }
            ret = Math.min(ret, h + l);

        }
        System.out.println(ret);
    }
}
